package com.company.service;

import com.company.mapper.GoodsTypeMapper;
import com.company.model.GoodsType;
import com.company.utils.DatabaseUtil;
import com.company.utils.MessageResponse;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class GoodsTypeService {
    public static SqlSession sqlSession = DatabaseUtil.getSession();
    public static GoodsTypeMapper goodsTypeMapper = sqlSession.getMapper(GoodsTypeMapper.class);

    public static List<GoodsType> findAll() {
        return goodsTypeMapper.findAll();
    }

    public static MessageResponse<Boolean> insertOne(GoodsType type) {
        goodsTypeMapper.insertOne(type);
        sqlSession.commit();

        return new MessageResponse<>(
                "insert success",
                true
        );
    }

    public static MessageResponse<Boolean> deleteOne(int id) {
        goodsTypeMapper.deleteOne(id);
        sqlSession.commit();

        return new MessageResponse<>(
                "delete success",
                true
        );
    }

    public static MessageResponse<Boolean> updateOne(GoodsType type) {
        goodsTypeMapper.updateOne(type);
        sqlSession.commit();

        return new MessageResponse<>(
                "update success",
                true
        );
    }
}
